import { finishWorkOrderApi } from "@/api/waybillManagement/workOrder";
import { Modal, message } from "ant-design-vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
import { createVNode } from "vue";

export default function OperationHook(state: Base.GeneraDataType) {
  const { dialogOpts, passData, init } = state;

  //完成进度
  const updateFinishdle = () => {
    Modal.confirm({
      title: "确认将工单变为处理完成状态吗?",
      icon: createVNode(ExclamationCircleOutlined),
      content: "",
      okText: "确定",
      okType: "danger",
      cancelText: "取消",
      onOk() {
        finishWorkOrderApi(passData.value.id).then((res: any) => {
          const { code } = res;
          if (code === 200) {
            message.success("操作成功!");
            init(passData.value.id);
          }
        });
      }
    });
  };

  // 更新进度
  const updateSchedulekHandle = () => {
    dialogOpts.title = `更新进度`;
    dialogOpts.width = "520px";
    dialogOpts.component = "UploadFile";
    dialogOpts.passData = passData.value;
    dialogOpts.type = 1;
    dialogOpts.visible = true;
  };
  return {
    updateFinishdle,
    updateSchedulekHandle
  };
}
